<?php
namespace App\Common\Cla\Rbac\User\Relation\Base;

use App\Common as com;
use App\Common\Cla\Rbac\User\Relation\Base\OfIdOrObj as nameOfIdObj;
use App\Common\Cla\Rbac\User\Relation as nameRelation;

class OfIdOrObj extends com\Cla\ClaBase {

	private nameRelation\OfId $ofIdObj;

	private int $typeId;

	/**
	 * OfIdOrId constructor.
	 * @param nameRelation\OfId|int $ofIdOrObj
	 */
	public function __construct( nameRelation\OfId|int $ofIdOrObj ) {
		if( $ofIdOrObj instanceof nameRelation\OfId ){
			$this->ofIdObj = $ofIdOrObj;
		}else{
			$this->typeId = $ofIdOrObj;
		}
		//
		parent::__construct();
	}

	/**
	 * @return nameRelation\OfId
	 */
	public function getIdObj(  ):nameRelation\OfId {
		if( ! isset( $this->ofIdObj ) ){
			$this->ofIdObj = nameRelation\OfId::makeOfIdOrObj( $this->getId() );
		}
		return $this->ofIdObj;
	}

	/**
	 * @return int
	 */
	public function getId(  ):int {
		if( ! isset( $this->typeId ) ){
			$this->typeId = $this->getIdObj()->getId();
		}
		return $this->typeId;
	}

	// ===============================
	//
	//
	// 下面为静态方法
	//
	//
	// ===============================

	/**
	 * @param nameRelation\OfId|int $ofIdOrObj
	 * @return $this
	 */
	public static function makeOfIdOrObj( $ofIdOrObj ):self {
		return self::make( $ofIdOrObj );
	}

}
